package 华为;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class Main1 {
   public static Map<Character, Integer> map = new HashMap<>();
    {
        map.put('1', 1);
        map.put('2', 2);
        map.put('3', 3);
        map.put('4', 4);
        map.put('5', 5);
        map.put('6', 6);
        map.put('7', 7);
        map.put('8', 8);
        map.put('9', 9);
        map.put('A', 10);
        map.put('B', 11);
        map.put('C', 12);
        map.put('D', 13);
        map.put('F', 14);
    }
    public int lastWordLength(String str){
        if (str == null || str == ""){
            return 0;
        }
        String[] array = str.split(" ");
        String s = array[array.length - 1];
        return s.length();
    }

    public int countChar(String str, char target){
        if (str == null || str == ""){
            return 0;
        }
        char[] array = str.toCharArray();
        int count = 0;
        for(int i = 0; i < array.length ; i++){
            if (array[i] == target){
                count++;
            }
        }

        return count;

    }

    /**
     * 十六转10
     * @param num
     * @return
     */
    public static int toHex(String  num) {
       return  Integer.parseInt(num,16);
    }

    public static int toHex2(String  num) {
       int res = 0;
       char[] chars = num.toCharArray();
       for (int i = 0; i < chars.length; i++) {
           res  = res * 16 +  map.get(chars[i]);
       }
       return  res;
    }

    //求int型正整数在内存中存储时1的个数
    public static int  hj15(int num ){
       if (num == 0){
           return 0;
       }
       int count = 0;
       while (num > 0){
           if ((num & 1) == 1){
               count++;
           }
           num = num >>> 1;
       }
       return count;
    }
    public static int  hj15_V2(int num ){
       if (num == 0){
           return 0;
       }
        String s = Integer.toBinaryString(num);
       int count = 0;
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '1'){
                count++;
            }
        }
        return count;
    }


    ///购物单
    static class  GoodItem{
        int price;
        int weight;
    }
    public static int hj16() throws Exception{

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        String[] s1 = s.split(" ");
        int money = Integer.valueOf(s1[0]);
        int amount = Integer.valueOf(s1[1]);

        GoodItem[][] goodItems = new GoodItem[amount + 1][3];
        for (int i = 1; i <= amount; i++) {
             String[]   itemLines = br.readLine().split(" ");
             int price = Integer.valueOf(itemLines[0]);
             int weight = Integer.valueOf(itemLines[1]);
             int masterId = Integer.valueOf(itemLines[2]);
             GoodItem goodItem = new GoodItem();
             goodItem.price = price;
             goodItem.weight = weight;
             if (masterId == 0){
                 goodItems[i][0] = goodItem;
             }else{
                 if (goodItems[masterId][1] == null){
                     goodItems[masterId][1] = goodItem;
                 }else {
                     goodItems[masterId][2] = goodItem;
                 }
             }
        }
        return 0;
    }

    public static void main(String[] args) throws Exception{
        Random random = new Random();
        random.nextInt(500);
        Main1 main1 = new Main1();
        //System.out.println( main1.lastWordLength("main1"));
        //System.out.println( main1.countChar("main1a", 'a'));
        //System.out.println(toHex("AAB"));
        //System.out.println(toHex2("AAB"));
        //求int型正整数在内存中存储时1的个数
        //System.out.println(hj15_V2(7));
        //购物单
        System.out.println(hj16());
    }
}
